package cn.semcorp.zhuhaizj.controller;

import cn.semcorp.zhuhaizj.pojo.dto.AccountingUpdateChinese;
import cn.semcorp.zhuhaizj.pojo.dto.InsertInputOutputDTO;
import cn.semcorp.zhuhaizj.pojo.dto.SelectMaterialsDTO;
import cn.semcorp.zhuhaizj.pojo.vo.CommonVO;
import cn.semcorp.zhuhaizj.pojo.vo.MaterialsVO;
import cn.semcorp.zhuhaizj.pojo.vo.MixturesVO;
import cn.semcorp.zhuhaizj.restful.JsonResult;
import cn.semcorp.zhuhaizj.services.impl.AccountingServiceImpl;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/accounting")
@Api(tags ="账务")
public class AccountingController {
    @Autowired
    private AccountingServiceImpl accountingService;

    @PostMapping( "/clickUpload")
    public JsonResult upLoadNormal(@RequestBody List<AccountingUpdateChinese> list){
            accountingService.upLoadNormal(list);
            return JsonResult.ok("成功导入"+list.size()+"条记录!");
    }

    @PostMapping( "/abnormalUpload/{date}")
    public JsonResult upLoadAbnormal(@RequestBody List<AccountingUpdateChinese> list,@PathVariable String date){
            accountingService.upLoadAbnormal(list,date);
            return JsonResult.ok("追加导入"+list.size()+"条记录成功!");
    }

    @GetMapping("/selectMixtures")
    public JsonResult queryMixtures(String workshop,String model){
        //<Map<String, List<MixturesVO>>>
            return JsonResult.ok(accountingService.queryMixtures(workshop,model),"涂布混合料库存趋势查询成功!");
    }


    @GetMapping("/selectMaterials")
    public JsonResult queryMaterials(String workshop,String model){
        //<Map<String, List<MaterialsVO>>>
            return JsonResult.ok(accountingService.queryMaterials(workshop,model),"原料库存趋势查询成功!");
    }

    /**
     * 查询原料利用
     */
    @GetMapping("/select/materials/utilization")
    public JsonResult queryMaterialsUtilization(SelectMaterialsDTO dto){
        //<Map<String, List<MaterialsVO>>>
            return JsonResult.ok(accountingService.queryMaterialsUtilization(dto),"原料利用查询成功!");
    }

    /**
     * 导入产出数据
     */
    @PostMapping("/insert/input/output")
    public JsonResult insertInputOutput(@RequestBody List<InsertInputOutputDTO> list){
            accountingService.insertInputOutput(list);
            return JsonResult.ok("成功导入"+list.size()+"条数据!");
    }

    @GetMapping("/select/workshop")
    public JsonResult selectWorkshop(){
            return JsonResult.ok(accountingService.selectWorkshop());
    }
}


